package org.frvi.goldspring.web.wicket.validator;

import org.apache.wicket.injection.web.InjectorHolder;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.apache.wicket.validation.IValidatable;
import org.apache.wicket.validation.validator.AbstractValidator;
import org.apache.wicket.validation.validator.StringValidator;
import org.frvi.goldspring.business.service.AccountService;

import java.util.Map;

/**
 * User: Frank
 * Date: Oct 11, 2009
 * Time: 10:43:26 PM
 * To change this template use File | Settings | File Templates.
 */
public class UniqueAccountNameValidator extends StringValidator {

    @SpringBean
    private AccountService service;

    public UniqueAccountNameValidator() {
        InjectorHolder.getInjector().inject(this);

    }

    @Override
    protected void onValidate(IValidatable<String> validatable) {
        if (service.findByName(validatable.getValue()) != null)  {
            error(validatable);
        }
    }


}
